class Solution {
    public:
        long long countGood(vector<int>& nums, int k) {
            unordered_map<int,int> window;
            int cnt = 0;
            int n = nums.size();
            int left = 0;
            long long ans = 0;
            for(int i = 0;i < n;i++){
                
                cnt += window[nums[i]];
                window[nums[i]]++;
                
                while(cnt >= k){
                    window[nums[left]]--;
                    cnt -= window[nums[left]];
                    left++;
                }
                // cout << i << ' ' << left << endl; 
                ans += left;
            }
            return ans;
        }
    };
    